package com.xiaoxu.media.controller;

import com.xiaoxu.base.exception.bkSchoolException;
import com.xiaoxu.base.model.RestResponse;
import com.xiaoxu.media.model.po.MediaFiles;
import com.xiaoxu.media.service.MediaFileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author xiaoxu
 * @version 1.0
 * @description TODO
 * @date 2023/1/29 21:07
 */
@Api(value = "媒资文件管理接口", tags = "媒资文件管理接口")
@RestController
@RequestMapping("/open")
public class MediaOpenController {
    private final MediaFileService mediaFileService;

    public MediaOpenController(MediaFileService mediaFileService) {
        this.mediaFileService = mediaFileService;
    }

    @ApiOperation("预览文件")
    @GetMapping("/preview/{mediaId}")
    public RestResponse<String> getPlayUrlByMediaId(@PathVariable Long mediaId) {

        MediaFiles mediaFiles = mediaFileService.getFileById(mediaId);
        if (mediaFiles == null || StringUtils.isEmpty(mediaFiles.getUrl())) {
            throw new bkSchoolException("视频还没有转码处理");
        }
        return RestResponse.success(mediaFiles.getUrl());

    }

}
